package com.mdd.maduoduo.utils;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.mdd.maduoduo.R;

public class LoadingUtils {

    private static ViewGroup overlay;

    public static void showLoading(Activity activity) {
        if (overlay != null && overlay.getParent() != null) {
            return;
        }

        ViewGroup rootView = activity.findViewById(android.R.id.content);
        overlay = (ViewGroup) LayoutInflater.from(activity)
                .inflate(R.layout.loading_overlay, rootView, false);

        rootView.addView(overlay);
    }

    public static void hideLoading() {
        if (overlay != null && overlay.getParent() != null) {
            ((ViewGroup) overlay.getParent()).removeView(overlay);
        }
    }
}
